const fs = require('fs');
const path = require('path');
const login = require('../controller/admin/login');
const adminIndex = require('../controller/admin/index');
const checkAdminUser = require('../utils/userStatus').checkUserStatus;
const logoutAdminStatus = require('../utils/userStatus').destroyUserStatus;
const userList = require('../controller/admin/userList');
const addUser = require('../controller/admin/addUser');
const updateUser = require('../controller/admin/userInfo');
const changePw = require('../controller/admin/changePw');
const test = require('../controller/admin/test').test;
const huayuList = require('../controller/admin/huayuList');
const addFlower = require('../controller/admin/addHuayu');
const updateFlower = require('../controller/admin/updateFlower');
const flowerPicList = require('../controller/admin/flowerPicList');
const addFlowerPic = require('../controller/admin/addFlowerPic');
const updateFlowerPic = require('../controller/admin/updateFlowerPic');
const fenxiang = require('../controller/web/fenxiang');
//web路由
const webIndex = require('../controller/web/index').page;
exports.router = function(app){
    app.get('/', (req, res, next) => {
      res.sendFile(path.join(__dirname,'../public/build/index.html'))
    })
    app.get('/mhjsq', (req, res, next) => {
      res.sendFile(path.join(__dirname,'../public/build/index.html'))
    })
    app.get('/fenxiang', fenxiang.page);
    // 添加花束
    app.get('/admin/addFlowerPic', checkAdminUser, addFlowerPic.page);
    // 花束列表
    app.get('/admin/flowerPicList', checkAdminUser, flowerPicList.page);
    app.get('/admin/flowerPicList/page/:page?', checkAdminUser, flowerPicList.page);
    // 更新花语
    app.get('/admin/updateFlower', checkAdminUser, updateFlower.page);
    // 添加花语
    app.get('/admin/addFlower', checkAdminUser, addFlower.page);
    // 花语列表
    app.get('/admin/huayuList', checkAdminUser, huayuList.page);
    app.get('/admin/huayuList/page/:page?', checkAdminUser, huayuList.page);
    // CMS登录页面
    app.get('/admin/login', login.page);
    // cms首页
    app.get('/admin/', checkAdminUser, adminIndex.page);
    // cms用户列表
    app.get('/admin/userList', checkAdminUser, userList.page);
    app.get('/admin/userList/page/:page?', checkAdminUser, userList.page);
    // 添加cms用户
    app.get('/admin/addUser', checkAdminUser, addUser.page);
    // 修改密码
    app.get('/admin/changePw', checkAdminUser, changePw.page);
    // 更新用户
    app.get('/admin/updateUser', checkAdminUser, updateUser.page);
    //  CMS 登录接口
    app.post('/cms/getLogin', login.getLogin);
    // 退出系统接口
    app.post('/cms/logout', logoutAdminStatus);
    //  删除用户
    app.post('/cms/removeUserById', checkAdminUser, userList.removeUserById);
    // 添加用户接口
    app.post('/cms/addUser', checkAdminUser, addUser.addUser);
//    更新用户信息
    app.post('/cms/updateUser', checkAdminUser, updateUser.updateUser);
//    修改密码
    app.post('/cms/changePw', checkAdminUser, changePw.changePw);
//    web首页路由
//     app.get('/', function(req, res, next){
//         const file = fs.readFile('/public/build/index.html', function(err, data){
//             console.log(data);
//             res.send(data);
//         });
//     });
    app.post('/news/test', test);
    app.post('/cms/addFlower', checkAdminUser, addFlower.addFlower);
//    更新花语
    app.post('/cms/updateFlower', checkAdminUser, updateFlower.updateFlower);
//    小程序 获取花语滚动焦点图
    app.post('/item/getXyhfSwiperList', huayuList.getXyhfSwiperList);
//    小程序 获取花语列表
    app.post('/item/getFlowerList', huayuList.getFlowerList);
//    添加花束接口
    app.post('/cms/addFlowerPic', checkAdminUser, addFlowerPic.addFlowerPic);
//    删除花束
    app.post('/cms/removeFlowerPicById', checkAdminUser, flowerPicList.removeFlowerPicById);
//    获取花束列表
    app.post('/item/getFlowerPicList', flowerPicList.getFlowerPicList);
//    获取花束图片
    app.post('/item/getFlowerPics', updateFlowerPic.getFlowerPics);
//    获取花语详情
    app.post('/item/getFlowerInfo', updateFlower.getFlowerInfo);
//    获取花瓶详情
    app.post('/item/getVase',(req, res, next)=>{
      const result = [
        {
          title: '【两件套】北欧玻璃花瓶透明彩色水培植物干花欧式客厅插花摆件',
          pic: 'p1.jpg',
          price: '19.9',
          id: '1'
        },
        {
          title: '法兰晶 欧式花瓶轻奢花瓶玻璃花瓶客厅摆件插花瓶北欧刻花金边花瓶插花瓶 20四方花瓶随机发买一送一',
          pic: 'p2.jpg',
          price: '39.9',
          id: '2'
        },
        {
          title: '佳佰 25cm不规则纹理陶瓷花瓶 北欧简约田园艺术现代家居装饰摆设花插',
          pic: 'p3.jpg',
          price: '39.9',
          id: '3'
        },
        {
          title: '佳佰 17cm送麻绳防滑垫陶瓷花瓶 北欧田园艺术风格圆口袋 简约家居装饰现代摆设花插',
          pic: 'p4.jpg',
          price: '26.99',
          id: '4'
        },
        {
          title: '法兰晶 玻璃花瓶金边锤纹花瓶方形方口水培富贵竹花瓶 高25cm口径8cm口部描金',
          pic: 'p5.jpg',
          price: '46',
          id: '5'
        },
        {
          title: '【京东】法兰晶 轻奢烟灰描金北欧水晶花瓶玻璃花瓶插花瓶餐桌摆件水培绿萝 烟灰描金25CM*13CM中号单只装',
          pic: 'p6.jpg',
          price: '55.9',
          id: '6'
        }
      ];
      res.send(result);
    });
};